package com.tanhua.manager.listeners;

import cn.hutool.core.date.DateTime;
import com.tanhua.domain.db.Log;
import com.tanhua.manager.service.LogService;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

@Component
@RocketMQMessageListener(topic = "log_type_topic",consumerGroup = "logTypeGroup")
public class LogLinstener implements RocketMQListener<Map> {


    @Autowired
    private LogService logService;

    @Override
    public void onMessage(Map map) {
//        这里有个坑 明明放进去的是一个Long。但是这里取的时候是Integer
        Long userId = Long.parseLong( map.get("userId").toString())  ;
        String logTime = (String) map.get("logTime");
        String type = (String) map.get("type");

        Log log = new Log();
        log.setUserId(userId);
        log.setLogTime(logTime);
        log.setPlace("北京");
        log.setEquipment("华为p40");
        log.setType(type);

        try {
            logService.save(log);
        } catch (Exception e) {
//           写入到一个日志文件中
        }

        System.out.println("log已经保存成功..............");

    }
}
